import { Controller } from 'egg';

export default class GoodsAttrController extends Controller {

 // 商品类型所有列表
 async all() {
  const result = await this.ctx.service.goods.keywords.model.findAll({
    where: {
      status: 1
    },
  });

  if (result) {
    this.ctx.success({
      data: result
    });
  }
}


  // 商品类型列表
  async list() {
    const { page, pageSize, ...where } = this.ctx.validateReq(
      'goods.keywords.list',
    ).query;

    const result = await this.ctx.service.goods.keywords.index(page, pageSize, where);

    if (result) {
      this.ctx.success({
        data: result
      });
    }
  }


  // 新建商品类型
  async create() {
    const { body } = this.ctx.validateReq('goods.keywords.create');


    const result = await this.ctx.service.goods.keywords.create(body);

    if (result) {
      this.ctx.success({
        data: {
          id: result.id,
        },
        status: 201,
      });
    }
  }


  // 编辑商品类型
  async update() {

    const { body, params: { id } } = this.ctx.validateReq('goods.keywords.update');



    const result = await this.ctx.service.goods.keywords.update(id, body);

    if (result) {
      this.ctx.success({
        data: {
          id: result.id,
        }
      });
    }
  }


  // 删除商品类型
  async destroy() {
    const { params: { id } } = this.ctx.validateReq('goods.keywords.destroy');

    const result = await this.ctx.service.goods.keywords.destroy(id);

    if (result) {
      this.ctx.success({
        data: {
          id: result.id,
        }
      });
    }
  }

}
